package com.duobaoyu.dby.supply.api.service.rule.order.handler;

import com.duobaoyu.dby.supply.api.service.rule.order.bean.OrderAsyncRule;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceApiClient;
import com.duobaoyu.dby.supply.biz.service.rule.AbstractRule;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName LargeAmountOrderRule
 * @Description 大额订单判断规则
 * @createTime 08:56:00 2023/10/11
 */
@Component
@RequiredArgsConstructor
public class LargeAmountOrderRule extends AbstractRule<OrderAsyncRule> {

    private final ResourceApiClient resourceApiClient;

    @Override
    protected boolean executeRule(OrderAsyncRule orderAsyncRule) {
		BigDecimal orderAmount = orderAsyncRule.getSkuInfoList().stream()
				.map(skuInfo -> BigDecimal.valueOf(skuInfo.getSkuNum()).multiply(skuInfo.getPlatformPrice()))
				.reduce(BigDecimal.ZERO, BigDecimal::add);
		return resourceApiClient.largeOrderCheck(orderAmount);
    }
}
